package Game;

import java.util.ArrayList;
public class Group implements Cloneable{
    public Position position;
//    Object obj ;
    /*
    * 为了方便碰撞检测写的getRadius方法
    * 用LogicX、LogicY加上Radius得到Border
    * 如果border触及到边界
    *   再计算blocks的物理位置是否触及到边界
     */

    public ArrayList<Block> blocks;

    public Group(int x, int y){
        this.position = new Position(x ,y);
        this.blocks = new ArrayList<>();
    }
    public Group(){
        this.position = new Position();
        this.blocks = new ArrayList<>();
    };

    public void rotate (){
        //System.out.println( "Rotating" );
        for (Block block : this.blocks){
            block.position.rotate();
        }
    };

    public void rotate_back(){
        for (Block block : this.blocks){
            block.position.rotate_back();
        }
    }

    public void move(ActionType dir){
        if (dir ==  ActionType.ROTATE){
            this.rotate();
            return;
        }
        if (dir ==  ActionType.ROTATE_BACK){
            this.rotate_back();
            return;
        }

        this.position.move(dir);
    }

    @Override
    public Group clone() throws CloneNotSupportedException {
        Group cloned = (Group) super.clone();
        cloned.position = this.position.clone();
        cloned.blocks = new ArrayList<>();

//        System.out.println(this.blocks.size());
        for (int i = 0 ; i < this.blocks.size() ; i ++){
            cloned.blocks.add(this.blocks.get(i).clone());
        }

        return cloned;
    }
}
